using System.Collections.Generic;
using System.Text;


namespace HEFramework
{
    internal class LangOutput
    {
        private HashSet<string> sheetHashset = new();
        private StringBuilder outputContent = new();

        public string AddContent(string _fileName, string _sheetName, Property _property, string _content, string _id)
        {
            if (!sheetHashset.Contains(_fileName + _sheetName))
            {
                outputContent.Append("\n");
                DataTableTemplate.Inst.AppendLangOutputNote(outputContent, _fileName, _sheetName, _property.Name);
                sheetHashset.Add(_fileName + _sheetName);
            }

            string key = DataTableTemplate.Inst.GetLangOutputKey(_sheetName, _property.Name, _id);
            outputContent.Append("\n");
            DataTableTemplate.Inst.AppendLangOutputItem(outputContent, key, _content);
            return key;
        }

        public void Save()
        {
            if (outputContent.Length != 0)
            {
                outputContent.Insert(0, DataTableTemplate.Inst.GetLangOutputStartWith());
                outputContent.Append("\n");
                outputContent.Append(DataTableTemplate.Inst.GetLangOutputEndWith());
                System.IO.File.WriteAllText(DataTableSettingScriptableObject.Instance.SaveOutputKeyPath + "/Default.txt", outputContent.ToString());
            }
        }
    }
}